<?php

namespace App\Controllers;

class Cba extends BaseController {

    public function index() {

        // connect to the model
        $player = new \App\Models\player();
        // retrieve all the records
        $records = $player->findAll();

        $table = new \CodeIgniter\View\Table();
        $headings = $player->fields;
         $displayHeadings = array_slice($headings, 1, 3);
          $table->setHeading(array_map('ucfirst', $displayHeadings));


        $table->setHeading(['Name', 'Description','Link']);

        foreach ($records as $record) {
            $nameLink = anchor("Cba/showme/$record->id", 'details');
            $table->addRow($record->name,"<img src='image/".$record->image."' height=100 />",$nameLink);
        }


        $template = [
            'table_open' => '<table cellpadding="5px">',
            'cell_start' => '<td style="border: 1px solid #dddddd;">',
            'row_alt_start' => '<tr style="background-color:#dddddd">',
        ];
        $table->setTemplate($template);

        $fields = [
            'title' => 'Cba player',
            'heading' => 'Cba player',
            'footer' => 'Copyright XiangZexin'
        ];

        // get a template parser
        $parser = \Config\Services::parser();
        // tell it about the substitions
        return $parser->setData($fields)
                        ->render('templates\top') .
                $table->generate() .
                        $parser->setData($fields)
                        ->render('templates\bottom');
    }

     public function showme($id) {
        // connect to the model
        $player = new \App\Models\player();
        // retrieve all the records
        $record = $player->find($id);

        $table = new \CodeIgniter\View\Table();
        $table->addRow('Name', $record['name']);
        $table->addRow('city', $record['city']);
        $table->addRow('age', $record['age']);
        $table->addRow('playernumber', $record['playernumber']);
        $table->addRow('colour', $record['colour']);
        $table->addRow('Description', $record['description']);
       
        $table->addRow('Image', '<img src="../../image/'.$record['image'].'"/>');
        $nameLink = anchor( "/",'back');
        $table->addRow($nameLink);
        
  
          
        $template = [
            'table_open' => '<table cellpadding="5px">',
            'cell_start' => '<td style="border: 1px solid #dddddd;">',
            'row_alt_start' => '<tr style="background-color:#dddddd">',
        ];
        $table->setTemplate($template);

        $fields = [
            'title' => 'player Destinations',
            'heading' => 'player Destinations',
            'footer' => 'Copyright XiangZexin'
        ];
        //$table->setHeading(['name','Description','Link'] );
        // get a template parser
        $parser = \Config\Services::parser();

        $fields = [
            'title' => 'Cba player', 'heading' => 'Cba player', 'footer' => 'Copyright XiangZexin'
        ];

        // tell it about the substitions
        return $parser->setData($fields)
                        ->render('templates\top') .
                $table->generate() .
                        $parser->setData($fields)
                        ->render('templates\bottom');
    }

}